<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of uniform_zones_controller
 *
 * @author root
 */
class UniformZonesController extends AppController {

    //put your code here
    var $name = "UniformZones";

    function index($predio) {
        $this->UniformZone->recursive = -1;
        $zonas = $this->UniformZone->find('all', array('conditions' => array('UniformZone.property_id' => $predio)));
        $this->set('zonas', $zonas);
        $this->set('predio', $predio);
    }

    function add($predio) {
        if (empty($this->data)) {
            $this->data['UniformZone']['property_id'] = $predio;
        } else {

            if ($this->UniformZone->save($this->data)) {
                $this->Session->setFlash('Zona adicionada con éxito');
                $this->redirect(array('controller' => 'UniformZones', 'action' => 'index', $predio));
            }
        }
    }

    function edit($zona) {
        if (empty($this->data)) {
            $this->data = $this->UniformZone->find('first', array('conditions' => array('UniformZone.id' => $zona)));
        } else {
            if ($this->UniformZone->save($this->data)) {
                $this->Session->setFlash('Zona editada con éxito');
                $this->redirect(array('controller' => 'UniformZones', 'action' => 'index', $this->data['UniformZone']['property_id']));
            } else {
                $this->Session->setFlash('Error guardando datos');
            }
        }
    }

    function delete($id, $predio) {
        if ($this->UniformZone->delete($id)) {
            $this->Session->setFlash('Zona editada borrada con éxito');
            $this->redirect(array('controller' => 'UniformZones', 'action' => 'index', $predio));
        }
    }

}

?>
